package cn.zswltech.gruul.web.api.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @description:
 * @author: quanhong.ding
 * @create: 2020-12-08 19:39
 **/
public class OmnipotentCookieUtil {

    public static void main(String[] args) {
        String wlToken = "eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJjYjllMzYzZTQ4YTg0N2IyYmFlNjAxNTcyZWQ1YjdmNyIsInN1YiI6IkFwaUF1dG9UZXN0IiwiaXNzIjoiZnJhdWRtZXRyaXgiLCJpYXQiOjE2MDc0MjYwODcsImV4cCI6MTYyMjk3ODA4N30.dfH1icnpa7yw-pCO6D87nY1BMUY4ppSP5yzrjhhLhJI";
        String encryptCSRFToken = TokenUtil.encryptAsString("J9.eyJqdGkiOiJjYjllMzYzZTQ4YTg0N2IyYmFlNjAxNTcyZWQ1Yjdm|18|73", TokenUtil.CSRF_TOKEN_PUBLICKEY);
        String csrfTokenMix = TokenUtil.decrypt(encryptCSRFToken, TokenUtil.CSRF_TOKEN_PRIVATE);
        System.out.println(encryptCSRFToken);
        String[] csrfs = csrfTokenMix.split("\\|");
        int start = Integer.parseInt(csrfs[csrfs.length - 2]);
        int end = Integer.parseInt(csrfs[csrfs.length - 1]);
        List<String> csrfsList = new ArrayList<>(Arrays.asList(csrfs));
        csrfsList.remove(String.valueOf(start));
        csrfsList.remove(String.valueOf(end));
        String crsfToken = String.join("|", csrfsList);
        if (!crsfToken.equals(wlToken.substring(start, end))) {
            System.out.println("11111");
        }else {
            System.out.println("222");
        }
        String decodeStr = wlToken.substring(start, end);
        System.out.println(decodeStr);

    }
}
